package com.sharepics.dao;

import java.util.Calendar;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.Query;
import com.sharepics.bean.Album;

@Repository
public class AlbumDAO {

	static {
        ObjectifyService.register(Album.class);
    }
	
	
	public AlbumDAO(){
		
	}
	
    public List<Album> findAll() {
        Objectify ofy = ObjectifyService.begin();
        Query<Album> q = ofy.query(Album.class);
        return q.list();
    }

    public Album get(long id) {
        Objectify ofy = ObjectifyService.begin();
        return ofy.find(Album.class, (long) id);
    }

    public void save(Album album) {
        Objectify ofy = ObjectifyService.begin();
        album.id = null;
        album.creationDate = Calendar.getInstance().getTime();
        ofy.put(album);
        System.out.println("Saving " + album);
    }
    
    public void update(Album album) {
        Objectify ofy = ObjectifyService.begin();
        ofy.put(album);
        System.out.println("Saving " + album);
    }
}
